# -*- coding:utf-8 -*-

"""
流程控制
if, else if, else, end
times, end
do, repeat if
while, end
"""
from selenium.webdriver.support.wait import WebDriverWait

"""
等待:
1、显示等待
from selenium.webdriver.support.wait import WebDriverWait
def document_initialised(driver):
    return driver.execute_script("return initialised")

driver.navigate("file:///race_condition.html")
WebDriverWait(driver, timeout=10).until(document_initialised)
el = driver.find_element(By.TAG_NAME, "p")
assert el.text == "Hello from JavaScript!"
  
  ############################
  
from selenium.webdriver.support.wait import WebDriverWait

driver.navigate("file:///race_condition.html")
el = WebDriverWait(driver, timeout=3).until(lambda d: d.find_element(By.TAG_NAME,"p"))
assert el.text == "Hello from JavaScript!"
  
2、隐式等待

driver = Firefox()
driver.implicitly_wait(10)
driver.get("http://somedomain/url_that_delays_loading")
my_dynamic_element = driver.find_element(By.ID, "myDynamicElement")


3、流畅等待
from selenium.webdriver.support.wait import WebDriverWait
driver = Firefox()
driver.get("http://somedomain/url_that_delays_loading")
wait = WebDriverWait(driver, timeout=10, poll_frequency=1, ignored_exceptions=[ElementNotVisibleException, ElementNotSelectableException])
element = wait.until(EC.element_to_be_clickable((By.XPATH, "//div")))
"""
# from selenium.webdriver.support.ui import WebDriverWait
# from selenium.webdriver.support import expected_conditions as EC
# # 等待新窗口或标签页
# WebDriverWait.until(EC.number_of_windows_to_be(2))

import time
from selenium.webdriver.remote.webdriver import WebDriver


class Control:
    def __init__(self, driver: WebDriver):
        self.driver = driver

